using System;
using System.Collections.Generic;
using System.Windows.Forms;
using RollManager.Library.Dialogs;

namespace RollManager.Library.ActionSteps
{
    [Serializable]
    public class ChooseServerGroupStep : ActionStep
    {
        public override string Name
        {
            get { return "Choose Server Group"; }
        }

        protected override void Run()
        {
            selectServerGroup();
        }

        protected override void Simulate()
        {
            selectServerGroup();
        }

        private void selectServerGroup()
        {
            // Create and show dialog to choose sub-folder.
            ChooseServerGroupDialog dialog = new ChooseServerGroupDialog();
            DialogResult result = dialog.ShowDialog();

            if( result == DialogResult.OK )
            {
                Progress.AddFormat( "Server Group selected: {0}", dialog.SelectedServerGroup.Name );

                List<string> servers = new List<string>();
                foreach( Server server in Database.GetServers( dialog.SelectedServerGroup.Id ) )
                {
                    servers.Add( server.Name );
                }

                Output = servers;
            }
            else
            {
                throw new Exception( "User cancelled server group selection." );
            }
        }
    }
}
